﻿#region Using namespaces...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
#endregion

namespace TaxonomyImportLibrary.Support
{
	/// <summary>
	/// FratureActivator class
	/// </summary>
	public class FeatureActivator
	{
		#region Singleton Members
		/// <summary>
		/// Singleton member instance
		/// </summary>
		static private volatile FeatureActivator _instance;
		/// <summary>
		/// Singleton sinchronization object
		/// </summary>
		static private object _sync = new object();
		#endregion

		#region Singleton Properties
		/// <summary>
		/// Gets Singleton instance
		/// </summary>
		static public FeatureActivator Instance
		{
			get
			{
				if (_instance == null)
				{
					lock (_sync)
					{
						if (_instance == null)
							_instance = new FeatureActivator();
					}
				}

				return _instance;
			}
		}
		#endregion

		#region Constructors
		/// <summary>
		/// Default constructor
		/// </summary>
		private FeatureActivator() { }
		#endregion

		#region Public Methods
		/// <summary>
		/// Handles activation of features for web applications
		/// </summary>
		/// <param name="properties"></param>
		/// <param name="guid"></param>
		public void ActivateSiteFeature(SPSite site, Guid guid)
		{
			// Activate feature
			if (site.Features.SingleOrDefault(x => x.DefinitionId == guid) == null)
				site.Features.Add(guid);
		}
		#endregion
	}
}
